home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / a86v302a.arc / 05EXCLUS.DOC < prev    next >
Encoding:
Text File  |  1987-04-24  |  8.5 KB  |  192 lines

  1. CHAPTER 5   SOME EXCLUSIVE FEATURES OF A86                5-1
  2.  
  3.  
  4. The IF Statement
  5.  
  6. As a "nudge" in the direction of structured programming, A86 
  7. offers the IF statement.  Suppose you want to conditionally skip 
  8. around just one instruction.  Ordinarily, this would require, for 
  9. example: 
  10.  
  11.   JNZ >L1    ; skip the following move if NZ
  12.   MOV AX,BX  ; make this move only if Z
  13. L1:          ; this label exists only for the above skip
  14.  
  15. You may replace the above code with the single line:
  16.  
  17.   IF Z MOV AX,BX
  18.  
  19. The above line generates exactly the same code as the previous 3 
  20. lines-- a conditional jump of the opposite condition, around the 
  21. statement given in the tail of the IF statement.  The statement 
  22. can be a macro call, giving you the opportunity to skip something 
  23. more complicated.
  24.  
  25. You may use any condition that would follow the "J" in a 
  26. conditional jump instruction, except CXZ, which does not have a 
  27. reverse condition.  The assembler interprets the condition by 
  28. appending a "J" to the beginning of the condition; so that the 
  29. symbols "C", "NC", "Z", "NZ", etc. are not reserved by the 
  30. assembler, and can be defined in other contexts.  
  31.  
  32.  
  33. Multiple operands to PUSH, POP, INC, DEC
  34.  
  35. A86 will accept any number of register operands for the 
  36. instructions PUSH, POP, INC, and DEC; it will generate the 
  37. appropriate machine instruction for each operand.  For example, 
  38. the statement PUSH AX,BX is the same as the two statements PUSH 
  39. AX and PUSH BX.  
  40.  
  41. A numeric operand appearing in an INC or DEC statement will cause 
  42. the previous INC(s) or DEC(s) to be propagated that number of 
  43. times.  For example, the statement INC AX,4 will generate 4 INC 
  44. AX instructions.  The statement DEC AL,BX,2 will generate DEC AL, 
  45. DEC BX, DEC AL, DEC BX.  Sorry, numeric operands are not allowed 
  46. if any of the operands affected was a forward-reference or 
  47. relocatable quantity; e.g., INC FOO,2 where FOO is undefined.  In 
  48. most such cases, you'll want to code the more effiecient ADD 
  49. FOO,2 anyway.
  50.  
  51.  
  52. Conditional Return Instructions
  53.  
  54. Programmers accustomed to the conditional-return instructions of 
  55. the 8080/Z80 will appreciate the following feature: A86 allows 
  56. the operand to a conditional jump instruction to be one of the 
  57. three RET instructions RET, RETF, or IRET.  The assembler will 
  58. find a nearby return-instruction of the indicated flavor, and use 
  59. that as the target for the conditional jump.  For example, JZ RET 
  60. is the replacement for the 8080's RZ return-if-zero instruction.  
  61.                                                           5-2
  62. In other 8086 assembly languages, you have to find the nearby 
  63. instruction yourself, attach a label to it, and use that label.  
  64. Note that it does not suffice to attach a label to a single RET 
  65. instruction and use that label throughout the program: the range 
  66. of conditional jumps is only 128 bytes in either direction.  
  67.  
  68. What happens if A86 does not find a nearby return instruction?  
  69. In that case, A86 issues an error, "02 Jump > 128", for the next 
  70. matching return-instruction in the program.  If there is no 
  71. subsequent return-instruction, the return-mnemonic will appear as 
  72. an undefined symbol at the end of the program.   In either case, 
  73. you correct the problem by inserting a free-standing return-
  74. instruction at some nearby point in the program, where it will 
  75. not affect the existing code (typically following an 
  76. unconditional JMP instruction).  If there is no good place to 
  77. insert a return-instruction, you can always replace the "Jcond 
  78. RET" with an "IF cond RET".  
  79.  
  80.  
  81. A86 extensions to the MOV instruction
  82.  
  83. There are a number of MOV instructions available in A86 that are 
  84. not a part of the machine instruction set.  
  85.  
  86. First, moves between segment registers are allowed.  For example, 
  87. if you code MOV ES,DS  , the assembler will generate a PUSH DS 
  88. followed by a POP ES; which will effect the move that you 
  89. intended.  
  90.  
  91. Second, MOV allows 3 operands.  A statement MOV x,y,z is 
  92. equivalent to the two statements MOV y,z followed by MOV x,y.  
  93. Sorry, but segment-overrides are not allowed in conjunction with 
  94. 3-operand MOVs.  The override preceding the MOV is ambiguous in 
  95. its meaning; and overrides within operands cannot be handled 
  96. correctly by A86.  You'll have to code two MOV instructions if 
  97. you want either or both to have a segment override.
  98.  
  99.  
  100. Local Labels
  101.  
  102. If you examine most assembly-language program symbol tables, you 
  103. will find that the symbols can be partitioned into two levels of 
  104. significance.   About half the symbols are the names of 
  105. procedures and variables having global significance.  If the 
  106. names of these symbols are chosen intelligently and carefully, 
  107. the program's readability improves drastically. (They usually 
  108. aren't chosen well, most often because the assembler restricts 
  109. symbols to 6 letters, or because the programmer's habits are 
  110. influenced by such assemblers.) 
  111.  
  112. The other half of the symbols in a program have a much lower, 
  113. local significance.  They are only place-markers used to 
  114. implement small loops and local branching (e.g., "skip the next 2 
  115. instructions if the Z-flag is set").  Assigning full-blown names 
  116. to these labels reduces the readability of your program in two 
  117. ways:  First, it is harder to recognize local jumps for what they 
  118. are-- they are usually the assembly-language equivalent of high-
  119. level language constructs like IF statements and WHILE-loops.  
  120.                                                           5-3
  121. Second, it is harder to follow the global, significant symbols 
  122. because they are buried in a sea of the place-marker symbols in 
  123. the symbol table.  
  124.  
  125. A86 solves this problem with local symbols.  If a symbol in your 
  126. program consists of a single letter followed by one or more 
  127. decimal digits (L3, X123, Y37, etc.), then the symbol is a local 
  128. symbol.  Local symbols do not appear in the A86 XREF cross-
  129. reference listing. They can also be redefined to something 
  130. completely different later in the program.  
  131.  
  132. Because local labels can be redefined, you must take care to 
  133. specify which one you are referring to in your program.  If your 
  134. reference is a forward-reference (the label occurs further down 
  135. in the program from the reference), then the reference must be 
  136. preceded by a ">".  For example, 
  137.  
  138. L2:
  139.   MOVSB
  140.   INC BX
  141.   LOOP L2    ; lack of ">" means L2 is above this statement
  142.   .
  143.   .
  144.   JNZ >L2    ; ">" indicates L2 is below this statement
  145.   .
  146.   .
  147. L2:
  148.  
  149. I recommend that you assign all your local labels the names L0 
  150. through L9.  If your program is so complex that it needs more 
  151. than 10 place-holders in any one stretch of code, then that 
  152. stretch needs to be rewritten.  
  153.  
  154.  
  155.  
  156. Operands to AAM and AAD Instructions
  157.  
  158. Those of you who have examined 86-family opcodes with an eagle-
  159. eye will have noticed a somewhat spurious "0A" opcode generated 
  160. after every AAM or AAD instruction.  The opcode is there to 
  161. provide the constant divisor or multiplicand for the instruction.  
  162. Believe it or not, there wasn't enough room in the microcode of 
  163. the original 8086 to hold this constant!  Although Intel has 
  164. never announced the generality of AAM and AAD, it is there: you 
  165. can substitute any other constant for 0A (decimal 10), and that 
  166. constant will be used.  A86 supports this by letting you give a 
  167. constant byte-sized operand to AAM or AAD.  Particularly useful 
  168. are the instructions AAM 16, which unpacks AL into nibbles AH and 
  169. AL; and AAD 16, which reverses the process, packing nibbles AH 
  170. and AL into AL.  
  171.  
  172. WARNING: A couple of my users point out to me that the AAD 
  173. instruction with a general operand won't work on the NEC V20 and 
  174. V30 chips.  The operand is assumed to be 10 no matter what it 
  175. really is.  Since a large number of PC "speed-up" kits involve 
  176. switching to NEC chips, this will be seen on many PC's.  You 
  177. should not use AAD with an operand if you want your program to 
  178. run on everybody's machine.  Too bad.  AAM works fine, though. 
  179.                                                           5-4
  180. Single-Operand Forms of the TEST Instruction
  181.  
  182. A86 allows the TEST instruction to have a single operand, to set 
  183. the flags according to the value of the operand.  If the operand 
  184. is a register, A86 generates a TEST of the register with itself.  
  185. If the operand is a memory quantity, A86 generates a TEST of the 
  186. memory with the constant -1 (i.e., the quantity will be ANDed 
  187. with an all 1's constant).  For example, instead of TEST DL,DL, 
  188. you can code simply TEST DL.  Instead of TEST WVAR,0FFFF, you can 
  189. code simply TEST WVAR.  
  190.  
  191.  
  192.